package com.basketball.gym.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.basketball.gym.pojo.Finance;
import com.basketball.gym.pojo.ResponseData;
import com.basketball.gym.pojo.User;
import com.basketball.gym.service.FinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 赵肖云
 * @since 2021-03-27
 */
@Api(tags = "流水管理")
@RestController
@RequestMapping("/gym/finance")
public class FinanceController {
    @Autowired
    private FinanceService financeService;

    @ApiOperation("查询个人流水（可通过type,paymentType筛选）")
    @GetMapping
    public ResponseData<List<Finance>> getFinance(Finance finance, @ApiIgnore @ModelAttribute("activeUser") User user) {
        return financeService.getFinance(finance, user);
    }

    @ApiOperation("管理员查询流水(可通过user_id,type,paymentType,user.phone筛选）")
    @PreAuthorize("hasAnyRole('admin','superAdmin')")
    @GetMapping("/admin")
    public ResponseData<IPage<Finance>> adminGetFinance(Finance finance) {
        return financeService.adminGetFinance(finance);
    }
}

